package com.example.test;


import cn.xnatural.enet.common.Log;
import cn.xnatural.enet.core.AppContext;
import cn.xnatural.enet.core.Environment;
import cn.xnatural.enet.core.GroovyEngine;
import cn.xnatural.enet.event.EL;
import cn.xnatural.enet.server.ServerTpl;
import cn.xnatural.enet.server.dao.hibernate.Hibernate;
import cn.xnatural.enet.server.dao.hibernate.TransWrapper;
import org.hibernate.SessionFactory;

import javax.annotation.Resource;

public class Launcher extends ServerTpl {
    final Log log = Log.of(getClass());
    @Resource
    SessionFactory sf;
    @Resource
    AppContext     ctx;
    @Resource
    Environment    env;


    public static void main(String[] args) {
        AppContext app = new AppContext();
        // app.addSource(new Hibernate().attr("hibernate.hbm2ddl.auto", "none"));
        app.addSource(new Launcher());
        app.start();
    }


    @Resource
    TransWrapper tm;

    @EL(name = "sys.started")
    protected void sysStarted() {
        try {
            bean(GroovyEngine.class).script("readDoc.groovy", script -> {
                script.setProperty("log", Log.of(script.getClass()));
                script.run();
            });
        } finally {
            ctx.stop();
        }
    }

}
